package com.tripcube.file.config;

import com.tripcube.file.service.*;
import com.tripcube.file.service.impl.AliyunOssSysFileServiceImpl;
import com.tripcube.file.service.impl.LocalSysFileServiceImpl;
import com.tripcube.file.service.impl.MinioSysFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "file")
public class FileStorageConfig {

    /**
     * 存储方式: local, minio, aliyun
     */
    private String storage = "local";

    @Autowired
    private LocalSysFileServiceImpl localSysFileService;

    @Autowired
    private MinioSysFileServiceImpl minioSysFileService;

    @Autowired
    private AliyunOssSysFileServiceImpl aliyunOssSysFileService;

    @Bean
    public ISysFileService fileStorageService() {
        return switch (storage.toLowerCase()) {
            case "minio" -> minioSysFileService;
            case "aliyun" -> aliyunOssSysFileService;
            default -> localSysFileService;
        };
    }

    public String getStorage() {
        return storage;
    }

    public void setStorage(String storage) {
        this.storage = storage;
    }
}
